package cn.edu.neusoft.wuguangsheng.flowerimpression.activity;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import cn.edu.neusoft.wuguangsheng.flowerimpression.R;
import cn.edu.neusoft.wuguangsheng.flowerimpression.bean.SuccessBean;
import cn.edu.neusoft.wuguangsheng.flowerimpression.listener.TListener;
import cn.edu.neusoft.wuguangsheng.flowerimpression.model.UpdateKnowCommentModel;

public class UpdateCommentActivity extends BaseActivity implements View.OnClickListener{
    ImageView updatecomment_fh;
    EditText updatecomment_content;
    Button updatecomment_btn;

    String fkcid,fkccontent;

    @Override
    void initView() {
        setLayout_file(R.layout.activity_update_comment);
        fkcid = getIntent().getStringExtra("fkcid");
        fkccontent = getIntent().getStringExtra("fkccontent");

        updatecomment_fh = (ImageView)findViewById(R.id.updatecomment_fh);
        updatecomment_content = (EditText)findViewById(R.id.updatecomment_content);
        updatecomment_btn = (Button)findViewById(R.id.updatecomment_btn);

        updatecomment_content.setText(fkccontent);
    }

    @Override
    void initEvent() {
        updatecomment_fh.setOnClickListener(this);
        updatecomment_btn.setOnClickListener(this);

    }

    @Override
    void initDate() {

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.updatecomment_fh:
                finish();
                break;
            case R.id.updatecomment_btn:
                String content = updatecomment_content.getText().toString().trim();
                if (content.equals("")){
                    Toast.makeText(UpdateCommentActivity.this,"评论内容不能为空",Toast.LENGTH_SHORT).show();
                }
                else {
                    UpdateKnowCommentModel updateKnowCommentModel = new UpdateKnowCommentModel();
                    updateKnowCommentModel.updateKnowComment(fkcid, content, new TListener<SuccessBean>() {
                        @Override
                        public void onResponse(SuccessBean successBean) {
                            if (successBean.getSuccess().equals("1")){
                                Toast.makeText(UpdateCommentActivity.this,"评论成功",Toast.LENGTH_SHORT).show();
                                finish();
                            }
                            else{
                                Toast.makeText(UpdateCommentActivity.this,"评论失败",Toast.LENGTH_SHORT).show();
                            }

                        }

                        @Override
                        public void onFail(String msg) {

                        }
                    });
                }

                break;
        }

    }
}
